// import { login, logout, getInfo } from '@/api/login'
// import { getToken, setToken, removeToken } from '@/utils/auth'
import Cookies from 'js-cookie'
const user = {
  state: {
    allAuth: '',
    mid: '', // 菜单栏id
    sid: '',
    menu: '',
    userInfo: '',
    functionAuthState: ''
  },

  mutations: {
    SET_ALLAUTH: (state, allAuth) => {
      state.allAuth = allAuth
    },
    SET_FAS: (state, functionAuthState) => {
      state.functionAuthState = functionAuthState
    },
    SET_MID: (state, mid) => {
      state.mid = mid
    },
    SET_SID: (state, sid) => {
      state.sid = sid
    },
    SET_MENU: (state, menu) => {
      state.menu = menu
    },
    SET_USERINFO: (state, userInfo) => {
      state.userInfo = userInfo
    },
    RESET_USER: (state) => {
      for (var key in state) {
        state[key] = ''
      }
    }
  },

  actions: {
    resetUser ({ commit, state }, functionAuthState) {
      commit('RESET_USER')
      sessionStorage.clear()
    },
    setFunctionAuthState ({ commit, state }, functionAuthState) {
      commit('SET_FAS', functionAuthState)
      sessionStorage.setItem('functionAuthState', state.functionAuthState)
      Cookies.set('functionAuthState', state.functionAuthState)
    },
    setMid ({ commit, state }, mid) {
      commit('SET_MID', mid)
      sessionStorage.setItem('mid', state.mid)
      Cookies.set('mid', state.mid)
    },
    // 设置sessionid
    setSid ({ commit, state }, sid) {
      commit('SET_SID', sid)
      /** *本地持久化sid (选择一种就可以了)*/
      // 方法1，存入seesionStorage（该后台采用）
      sessionStorage.setItem('sid', state.sid)
      // 方法2，存入cook
      Cookies.set('sid', state.sid)
      // 方法3，存入localStorage（不建议）
    },
    logout ({ commit, state }) {
      sessionStorage.clear()
    },
    // 设置用户菜单权限
    setMenu ({ commit, state }, menu) {
      commit('SET_MENU', menu)
      sessionStorage.setItem('menu', JSON.stringify(state.menu))
    },
    // 设置用户基本信息
    setUserInfo ({ commit, state }, userInfo) {
      commit('SET_USERINFO', userInfo)
      sessionStorage.setItem('userInfo', JSON.stringify(state.userInfo))
    },
    // 设置用户所有权限
    setAllAuth ({ commit, state }, allAuth) {
      commit('SET_ALLAUTH', allAuth)
      sessionStorage.setItem('allAuth', JSON.stringify(state.allAuth))
    }
  }
}

export default user
